#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 105;
const double EPS = 1e-6;

int n, m;
int keyid;
struct Student {
  int id;
  string sid;
  int cid, rk;
  string name;
  int scores[4];
  int sum;
  double avg;
  bool operator<(Student stu) const { return sum > stu.sum; }
} students[N];
bool cmp_id(Student a, Student b) { return a.id < b.id; }
void sort_student() {
  sort(students + 1, students + n + 1);
  students[1].rk = 1;
  rep(i, 2, n) {
    if (students[i].sum == students[i - 1].sum)
      students[i].rk = students[i - 1].rk;
    else
      students[i].rk = i;
  }
}
void show_menu() {
  cout << "Welcome to Student Performance Management System (SPMS)." << endl;
  cout << endl;
  cout << "1 - Add" << endl;
  cout << "2 - Remove" << endl;
  cout << "3 - Query" << endl;
  cout << "4 - Show ranking" << endl;
  cout << "5 - Show Statistics" << endl;
  cout << "0 - Exit" << endl;
  cout << endl;
}
void add() {
  while (true) {
    cout
        << "Please enter the SID, CID, name and four scores. Enter 0 to finish."
        << endl;

    Student stu;
    cin >> stu.sid;
    if (stu.sid == "0") return;
    cin >> stu.cid >> stu.name;
    rep(i, 0, 3) cin >> stu.scores[i];
    bool fail = false;
    rep(i, 1, n) {
      if (students[i].sid == stu.sid) {
        cout << "Duplicated SID." << endl;
        fail = true;
        break;
      }
    }
    if (fail) continue;
    stu.sum = 0;
    rep(i, 0, 3) stu.sum += stu.scores[i];
    stu.avg = stu.sum / 4.0;
    stu.id = ++keyid;
    students[++n] = stu;
    sort_student();
  }
}
void remove() {
  while (true) {
    cout << "Please enter SID or name. Enter 0 to finish." << endl;
    string key;
    cin >> key;
    if (key == "0") return;
    int cnt = 0;
    rep(i, 1, n) {
      while (i <= n && (key == students[i].sid || key == students[i].name)) {
        swap(students[i], students[n]);
        --n;
        cnt++;
      }
    }
    sort_student();
    cout << cnt << " student(s) removed." << endl;
  }
}
void show_student(const Student& stu) {
  cout << stu.rk << ' ' << stu.sid << ' ' << stu.cid << ' ' << stu.name << ' ';
  rep(i, 0, 3) cout << stu.scores[i] << ' ';
  cout << stu.sum << ' ' << fixed << setprecision(2) << stu.avg;
  cout << endl;
}
void query() {
  while (true) {
    cout << "Please enter SID or name. Enter 0 to finish." << endl;
    string key;
    cin >> key;
    if (key == "0") return;
    vector<Student> res;
    rep(i, 1, n) {
      if (key == students[i].sid || key == students[i].name) {
        res.push_back(students[i]);
      }
    }
    sort(res.begin(), res.end(), cmp_id);
    for (Student& stu : res) show_student(stu);
  }
}
void show_rank() {
  cout << "Showing the ranklist hurts students' self-esteem. Don't do that."
       << endl;
}
void stat() {
  cout << "Please enter class ID, 0 for the whole statistics." << endl;
  int cid;
  cin >> cid;
  int m = 0;
  int a[4] = {0};
  int b[5] = {0};
  int sum[4] = {0};

  rep(i, 1, n) {
    if (!cid || students[i].cid == cid) {
      m++;
      rep(j, 0, 3) sum[j] += students[i].scores[j];
      rep(j, 0, 3) if (students[i].scores[j] >= 60) a[j]++;
      int tot = 0;
      rep(j, 0, 3) if (students[i].scores[j] >= 60) tot++;
      if (!tot) b[0]++;
      rep(j, 1, tot) b[j]++;
    }
  }
  double avg[4] = {0};
  rep(i, 0, 3) avg[i] = sum[i] * 1.0 / m;
  string major[4] = {"Chinese", "Mathematics", "English", "Programming"};
  rep(i, 0, 3) {
    cout << major[i] << endl;
    cout << "Average Score: " << fixed << setprecision(2) << avg[i] + EPS
         << endl;
    cout << "Number of passed students: " << a[i] << endl;
    cout << "Number of failed students: " << m - a[i] << endl;
    cout << endl;
  }
  cout << "Overall:" << endl;
  cout << "Number of students who passed all subjects: " << b[4] << endl;
  cout << "Number of students who passed 3 or more subjects: " << b[3] << endl;
  cout << "Number of students who passed 2 or more subjects: " << b[2] << endl;
  cout << "Number of students who passed 1 or more subjects: " << b[1] << endl;
  cout << "Number of students who failed all subjects: " << b[0] << endl;
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  while (true) {
    show_menu();
    int op;
    cin >> op;
    if (!op) break;
    if (op == 1) add();
    if (op == 2) remove();
    if (op == 3) query();
    if (op == 4) show_rank();
    if (op == 5) stat();
  }
  return 0;
}